package com.yaoweigroup.community.ui.home;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

import com.alipay.android.app.sdk.AliPay;
import com.hcinfos.gsoo.pay.Keys;
import com.hcinfos.gsoo.pay.Rsa;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.yaoweigroup.community.R;
import com.yaoweigroup.community.adapter.CommentAdapter;
import com.yaoweigroup.community.config.Common;
import com.yaoweigroup.community.config.Constant;
import com.yaoweigroup.community.config.Urls;
import com.yaoweigroup.community.enity.Comment;
import com.yaoweigroup.community.enity.Discount;
import com.yaoweigroup.community.enity.Group;
import com.yaoweigroup.community.enity.UserInfo;
import com.yaoweigroup.community.ui.bm.OrderSubmitActivity;
import com.yaoweigroup.community.ui.home.PostDetailActivity.MyImageGetter;
import com.yaoweigroup.community.ui.home.PostDetailActivity.MyImageGetter.URLDrawable;
import com.yaoweigroup.community.ui.my.MyDiscountActivity;
import com.yaoweigroup.community.ui.my.MyOrderActivity;
import com.yaoweigroup.community.util.BitmapHelp;
import com.yaoweigroup.community.util.DateUtil;
import com.yaoweigroup.community.util.DialogUtil;
import com.yaoweigroup.community.util.JsonUtil;
import com.yaoweigroup.community.util.LogUtil;
import com.yaoweigroup.community.util.LoginUtil;
import com.yaoweigroup.community.util.MD5;
import com.yaoweigroup.community.util.SharePreferenceUtil;
import com.yaoweigroup.community.util.Tools;
import com.yaoweigroup.community.util.UtilHttp;

public class DiscountDetailActivity extends Activity implements OnClickListener {

	private RelativeLayout left_rl;
	private Discount discount;
	private ImageView icon_iv;
	private TextView name_tv;
	private ImageButton add_ib;
	private TextView detail_num_tv;
	private ImageButton sub_ib;
	private TextView discount_tv;
	private TextView discount_num_tv;
	private TextView buyNum_tv;
	private TextView time_tv;
	private Button buy_btn;

	private BitmapUtils bitmapUtils;
	private BitmapDisplayConfig bigPicDisplayConfig;
	private int num = 1;

	private RelativeLayout comment_rl;
	private RelativeLayout group_detail_rl;
	private ImageView detail_iv;
	private ImageView comment_iv;
	private RelativeLayout content_detail_rl;
	private RelativeLayout content_comment_rl;
	private TextView content_tv;

	private ListView listView;
	private ProgressBar progress;
	private TextView empty_tv;
	private List<Comment> list;
	private ObjectMapper mapper;
	private CommentAdapter adapter;

	public final int COMMENT_SUCCESS = 0x2210;
	public final int COMMENT_FAIL = COMMENT_SUCCESS + 1;
	public final int SUBMIT_SUCCESS = COMMENT_SUCCESS + 2;
	public final int SUBMIT_FAIL = COMMENT_SUCCESS + 3;
	public final int RQF_PAY = COMMENT_SUCCESS + 4;

	public final int NEED_LOGIN = COMMENT_SUCCESS + 5;
	private TextView right_tv;
	private Dialog shareDialog;

	private TextView end_time_tv;

	private Dialog progressDialog;

	private SharePreferenceUtil util;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_discount_detail);
		util = new SharePreferenceUtil(this, Constant.prf);
		int width = this.getWindowManager().getDefaultDisplay().getWidth();
		Common.PROPORTION = width / 320f;
		Common.WIDTH = width;
		right_tv = (TextView) findViewById(R.id.right_tv);
		right_tv.setOnClickListener(this);
		list = new ArrayList<Comment>();
		adapter = new CommentAdapter(this, list);
		mapper = new ObjectMapper();
		end_time_tv = (TextView) findViewById(R.id.end_time_tv);
		empty_tv = (TextView) findViewById(R.id.empty_tv);
		progress = (ProgressBar) findViewById(R.id.progress);
		listView = (ListView) findViewById(R.id.listView);
		listView.setAdapter(adapter);
		content_tv = (TextView) findViewById(R.id.content_tv);
		content_comment_rl = (RelativeLayout) findViewById(R.id.content_comment_rl);
		content_detail_rl = (RelativeLayout) findViewById(R.id.content_detail_rl);
		comment_rl = (RelativeLayout) findViewById(R.id.comment_rl);
		comment_rl.setOnClickListener(this);
		group_detail_rl = (RelativeLayout) findViewById(R.id.group_detail_rl);
		group_detail_rl.setOnClickListener(this);
		detail_iv = (ImageView) findViewById(R.id.detail_iv);
		comment_iv = (ImageView) findViewById(R.id.comment_iv);
		bitmapUtils = BitmapHelp.getBitmapUtils(this);
		bigPicDisplayConfig = new BitmapDisplayConfig();
		bigPicDisplayConfig.setLoadFailedDrawable(this.getResources()
				.getDrawable(R.drawable.bucket_no_picture));
		bigPicDisplayConfig.setLoadingDrawable(this.getResources().getDrawable(
				R.drawable.bucket_no_picture));
		left_rl = (RelativeLayout) findViewById(R.id.left_rl);
		left_rl.setOnClickListener(this);

		discount = (Discount) getIntent().getSerializableExtra("discount");
		icon_iv = (ImageView) findViewById(R.id.icon_iv);
		add_ib = (ImageButton) findViewById(R.id.add_ib);
		add_ib.setOnClickListener(this);
		sub_ib = (ImageButton) findViewById(R.id.sub_ib);
		sub_ib.setOnClickListener(this);
		detail_num_tv = (TextView) findViewById(R.id.detail_num_tv);
		discount_tv = (TextView) findViewById(R.id.discount_tv);
		discount_num_tv = (TextView) findViewById(R.id.discount_num_tv);
		buyNum_tv = (TextView) findViewById(R.id.buyNum_tv);
		time_tv = (TextView) findViewById(R.id.time_tv);
		buy_btn = (Button) findViewById(R.id.buy_btn);
		buy_btn.setOnClickListener(this);
		name_tv = (TextView) findViewById(R.id.name_tv);
		shareDialog = createShareDialog(this);

		progressDialog = DialogUtil.createWaitDialog(this, "提交中...");

		if (discount != null) {
			bitmapUtils.display(icon_iv, discount.getImageurl(),
					bigPicDisplayConfig);
			discount_tv.setText("面值金额：¥" + discount.getPrice());

			time_tv.setText("开始时间:" + discount.getStarttime());
			buyNum_tv.setText("已有" + discount.getBuycount() + "人参与    已有"
					+ discount.getReadcount() + "人浏览");
			end_time_tv.setText("结束时间:" + discount.getEndtime());
			name_tv.setText(discount.getTitle());
			content_tv.setText(Html.fromHtml(discount.getDescription(),
					new MyImageGetter(this, content_tv), null));

			int start = DateUtil.compare_date2(discount.getStarttime());
			int end = DateUtil.compare_date2(discount.getEndtime());
			if (start < 0 && end > 0) {
				buy_btn.setVisibility(View.GONE);
				Toast.makeText(this, "已结束", 500).show();
			}

			obtainComment(discount.getId());
		}

	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		ShareSDK.initSDK(this);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.left_rl:
			finish();
			break;
		case R.id.add_ib:
			num += 1;
			detail_num_tv.setText(num + "");
			break;
		case R.id.sub_ib:
			num -= 1;
			if (num <= 0)
				num = 0;
			detail_num_tv.setText(num + "");
			break;
		case R.id.comment_rl:
			detail_iv.setVisibility(View.GONE);
			comment_iv.setVisibility(View.VISIBLE);
			content_detail_rl.setVisibility(View.GONE);
			content_comment_rl.setVisibility(View.VISIBLE);
			break;
		case R.id.group_detail_rl:
			detail_iv.setVisibility(View.VISIBLE);
			comment_iv.setVisibility(View.GONE);
			content_detail_rl.setVisibility(View.VISIBLE);
			content_comment_rl.setVisibility(View.GONE);
			break;
		case R.id.buy_btn:
			if (num == 0) {
				Toast.makeText(this, "购买数量不能为0", 500).show();
				return;
			}
			doOrder();
			// group.setNum(num);
			// Intent intent = new Intent(this, OrderSubmitActivity.class);
			// intent.putExtra("type", 0);//
			// // intent.putExtra("detail", group);
			// startActivity(intent);
			break;
		case R.id.right_tv:
			shareDialog.show();
			break;
		case R.id.wechat_tv:
			wechat();
			shareDialog.dismiss();
			break;
		case R.id.friend_tv:
			friend();
			shareDialog.dismiss();
			break;
		}

	}

	private String shareContent = null;
	private String shareUrl = null;
	private UserInfo user;

	private void doOrder() {

		user = (UserInfo) util.loadObject("user");
		if (user == null) {
			Toast.makeText(DiscountDetailActivity.this, "亲 请先登录，再操作!", 500)
					.show();
			return;
		}
		progressDialog.show();
		HttpUtils http = UtilHttp.getHttpUtils(this);
		RequestParams params = new RequestParams();
		JsonUtil jsonUtil = new JsonUtil();
		jsonUtil.add("Uid", user.getUid());
		jsonUtil.add("consignee", user.getUsername());
		jsonUtil.add("phoneNum", user.getPhone());
		jsonUtil.add("adress", user.getAddress());
		jsonUtil.add("ordersource", "手机APP");
		jsonUtil.add("remark", "备注");
		jsonUtil.add("ordertype", "优惠券");

		for (JsonUtil util : getShopStr()) {
			jsonUtil.add("orderdetailargs", util);
		}
		LogUtil.d("wxf", jsonUtil.toString());
		StringEntity enity = null;
		try {
			enity = new StringEntity(jsonUtil.toString(), "UTF-8");
		} catch (Exception e) {
			LogUtil.e("wxf", e.toString());
		}
		params.setContentType("application/json");
		params.setBodyEntity(enity);
		params.setHeader("Accept", "application/json");
		http.send(HttpRequest.HttpMethod.POST, Urls.submitPreferentialOrder,
				params, new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						LogUtil.d("wxf", "result = " + responseInfo.result);

						try {
							JSONObject obj = new JSONObject(responseInfo.result);

							int state = obj.getInt("state");
							String message = obj.getString("message");
							if (state == 200) {
								orderNum = obj.getString("orderNum");
								handler.sendEmptyMessage(SUBMIT_SUCCESS);
							} else if (state == 10000) {
								handler.sendEmptyMessage(NEED_LOGIN);
							} else {
								handler.sendEmptyMessage(SUBMIT_FAIL);
							}
						} catch (Exception e) {
							handler.sendEmptyMessage(SUBMIT_FAIL);

						}

					}

					@Override
					public void onFailure(HttpException error, String msg) {
						handler.sendEmptyMessage(SUBMIT_FAIL);

					}

				});
	}

	private List<JsonUtil> getShopStr() {
		if (discount == null)
			return null;
		List<JsonUtil> jsons = new ArrayList<JsonUtil>();
		JsonUtil utils = new JsonUtil();
		utils.add("productName", discount.getTitle());
		utils.add("productPrice", discount.getPrice() + "");
		utils.add("productCount", "1");
		utils.add("pid", discount.getId() + "");
		jsons.add(utils);
		return jsons;
	}

	private void wechat() {
		// if (group != null) {
		// shareContent = "优惠限时抢购#" + group.getPname() + "," + "¥ "
		// + group.getNewprice() + "#:#第一号秘书#";
		// wechatShare(1);
		// }
	}

	private void friend() {
		// if (group != null) {
		// shareContent = "优惠限时抢购#" + group.getPname() + "," + "¥ "
		// + group.getNewprice() + "#:#第一号秘书#";
		// if (group.getImageurl() == null
		// || group.getImageurl().length() == 0) {
		// Toast.makeText(this, "暂无图片url暂且不能分享", 500).show();
		// } else {
		// shareUrl = Urls.imgUrl + group.getImageurl();
		// wechatShare(0);
		// }
		// }

	}

	/**
	 * 微信分享
	 */
	private void wechatShare(int type) {

		String name = type == 0 ? WechatMoments.NAME : Wechat.NAME;
		Platform plat = ShareSDK.getPlatform(this, name);
		ShareParams sp = type == 0 ? getWechatMomentsShareParams()
				: getWechatShareParams();
		plat.share(sp);
		plat.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int arg1, Throwable arg2) {

				LogUtil.e("wxf", arg2.toString());
			}

			@Override
			public void onComplete(Platform arg0, int arg1,
					HashMap<String, Object> arg2) {

				Toast.makeText(DiscountDetailActivity.this, "分享成功", 500).show();
			}

			@Override
			public void onCancel(Platform arg0, int arg1) {

			}
		});
	}

	private ShareParams getWechatShareParams() {
		Wechat.ShareParams sp = new Wechat.ShareParams();
		sp.title = "第一号秘书分享";
		sp.text = shareContent;
		sp.shareType = Platform.SHARE_TEXT;
		return sp;
	}

	private ShareParams getWechatMomentsShareParams() {
		WechatMoments.ShareParams sp = new WechatMoments.ShareParams();
		sp.title = "第一号秘书分享";
		sp.text = shareContent;
		sp.imageUrl = shareUrl;
		sp.shareType = Platform.SHARE_IMAGE;
		return sp;
	}

	private int pageNo = 1;
	private int pageSize = 10;

	private void obtainComment(int id) {
		HttpUtils http = UtilHttp.getHttpUtils(this);
		RequestParams params = new RequestParams();
		JsonUtil jsonUtil = new JsonUtil();
		jsonUtil.add("id", id + "");
		jsonUtil.add("pageNo", pageNo + "");
		jsonUtil.add("pageSize", pageSize + "");
		LogUtil.d("wxf", jsonUtil.toString());
		StringEntity enity = null;
		try {
			enity = new StringEntity(jsonUtil.toString());
		} catch (Exception e) {
			LogUtil.e("wxf", e.toString());
		}
		params.setContentType("application/json");
		params.setBodyEntity(enity);
		params.setHeader("Accept", "application/json");
		http.send(HttpRequest.HttpMethod.POST, Urls.getProductComment, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						LogUtil.d("wxf", "result = " + responseInfo.result);
						String result = responseInfo.result;
						try {
							JSONObject obj = new JSONObject(result);
							int state = obj.getInt("state");
							String data = obj.getString("data");
							if (state == 200) {
								list = mapper.readValue(data,
										new TypeReference<List<Comment>>() {
										});
								handler.sendEmptyMessage(COMMENT_SUCCESS);

							} else {
								handler.sendEmptyMessage(COMMENT_FAIL);
							}
						} catch (Exception e) {
							handler.sendEmptyMessage(COMMENT_FAIL);

							LogUtil.e("wxf", e.toString());
						}

					}

					@Override
					public void onFailure(HttpException error, String msg) {
						LogUtil.e("wxf", error.toString());
					}

				});
	}

	Handler handler = new Handler() {

		public void handleMessage(android.os.Message msg) {
			progress.setVisibility(View.GONE);
			switch (msg.what) {
			case COMMENT_FAIL:

				break;
			case COMMENT_SUCCESS:
				if (list != null) {
					if (list.size() > 0) {
						empty_tv.setVisibility(View.GONE);
						adapter.setDataChange(list);
					} else {
						empty_tv.setVisibility(View.VISIBLE);
					}
				} else {
					empty_tv.setVisibility(View.VISIBLE);
				}
				break;
			case SUBMIT_FAIL:
				progressDialog.dismiss();
				Toast.makeText(DiscountDetailActivity.this, "提交失败", 500).show();
				break;
			case SUBMIT_SUCCESS:
				buy_btn.setVisibility(View.GONE);
				progressDialog.dismiss();
				pay();
				break;
			case RQF_PAY:
				Intent intent = new Intent(DiscountDetailActivity.this,
						MyDiscountActivity.class);
				startActivity(intent);
				finish();
				break;
			case NEED_LOGIN:
				LoginUtil.isLoginSuccess(DiscountDetailActivity.this, handler,
						mapper);
				break;
			case LoginUtil.LOGIN_SUCCESS:
				doOrder();
				break;
			case LoginUtil.LOGIN_FAIL:
				progressDialog.dismiss();
				Toast.makeText(DiscountDetailActivity.this, "提交失败", 500).show();

				break;
			}
		};
	};

	private TextView wechat_tv;
	private TextView friend_tv;

	private Dialog createShareDialog(Context context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		LinearLayout dialog_rl = (LinearLayout) inflater.inflate(
				R.layout.share_view, null);
		wechat_tv = (TextView) dialog_rl.findViewById(R.id.wechat_tv);
		wechat_tv.setOnClickListener(this);
		friend_tv = (TextView) dialog_rl.findViewById(R.id.friend_tv);
		friend_tv.setOnClickListener(this);
		final Dialog dialog = new Dialog(context, R.style.QuitDialog);
		dialog.setContentView(dialog_rl);
		Window dialogWindow = dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		dialogWindow.setGravity(Gravity.CENTER);
		lp.width = (int) (240 * Common.PROPORTION); // 宽度
		lp.height = (int) (110 * Common.PROPORTION); // 高度
		dialogWindow.setAttributes(lp);
		return dialog;
	}

	public class MyImageGetter implements ImageGetter {

		private Context context;
		private TextView tv;

		public MyImageGetter(Context context, TextView tv) {
			this.context = context;
			this.tv = tv;
		}

		@Override
		public Drawable getDrawable(String source) {
			// TODO Auto-generated method stub
			// 将source进行MD5加密并保存至本地
			if (!source.startsWith("http")) {
				source = "http://www.smartcity.sh" + source;
			}
			LogUtil.d("wxf", "source=" + source);
			String imageName = MD5.encode(source);
			String sdcardPath = Environment.getExternalStorageDirectory()
					.toString(); // 获取SDCARD的路径
			// 获取图片后缀名
			String[] ss = source.split("\\.");
			String ext = ss[ss.length - 1];

			// 最终图片保持的地址
			String savePath = sdcardPath + "/" + context.getPackageName() + "/"
					+ imageName + "." + ext;

			File file = new File(savePath);
			if (file.exists()) {
				// 如果文件已经存在，直接返回
				Drawable drawable = Drawable.createFromPath(savePath);
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
						drawable.getIntrinsicHeight());
				return drawable;
			}

			// 不存在文件时返回默认图片，并异步加载网络图片
			Resources res = context.getResources();
			URLDrawable drawable = new URLDrawable(
					res.getDrawable(R.drawable.bucket_no_picture));
			new ImageAsync(drawable).execute(savePath, source);
			return drawable;

		}

		private class ImageAsync extends AsyncTask<String, Integer, Drawable> {

			private URLDrawable drawable;

			public ImageAsync(URLDrawable drawable) {
				this.drawable = drawable;
			}

			@Override
			protected Drawable doInBackground(String... params) {

				InputStream in = null;// TODO Auto-generated method stub
				try {
					String savePath = params[0];
					String url = params[1];

					// 获取网络图片
					HttpGet http = new HttpGet(url);
					HttpClient client = new DefaultHttpClient();
					HttpResponse response = (HttpResponse) client.execute(http);
					BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(
							response.getEntity());
					in = bufferedHttpEntity.getContent();

					if (in == null)
						return drawable;

					File file = new File(savePath);
					String basePath = file.getParent();
					File basePathFile = new File(basePath);
					if (!basePathFile.exists()) {
						basePathFile.mkdirs();
					}
					file.createNewFile();
					FileOutputStream fileout = new FileOutputStream(file);
					byte[] buffer = new byte[4 * 1024];
					while (in.read(buffer) != -1) {
						fileout.write(buffer);
					}
					fileout.flush();
					Drawable mDrawable = Drawable.createFromPath(savePath);
					return mDrawable;

				} catch (Exception e) {
					try {
						if (in != null)
							in.close();
					} catch (Exception e2) {
						// TODO: handle exception
					}
				}
				return drawable;
			}

			@Override
			protected void onPostExecute(Drawable result) {
				// TODO Auto-generated method stub
				super.onPostExecute(result);
				if (result != null) {
					drawable.setDrawable(result);
					tv.setText(tv.getText()); // 通过这里的重新设置 TextView 的文字来更新UI
				}
			}

		}

		public class URLDrawable extends BitmapDrawable {

			private Drawable drawable = null;

			public URLDrawable(Drawable defaultDraw) {
				if (defaultDraw == null)
					return;
				setDrawable(defaultDraw);
			}

			private void setDrawable(Drawable nDrawable) {
				if (nDrawable == null)
					return;
				drawable = nDrawable;
				drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
						drawable.getIntrinsicHeight());
				setBounds(0, 0, drawable.getIntrinsicWidth(),
						drawable.getIntrinsicHeight());
			}

			@Override
			public void draw(Canvas canvas) {
				try {
					if (drawable != null) {
						drawable.draw(canvas);
					}
				} catch (StackOverflowError e) {

				}
			}

		}
	}

	/**
	 * 支付宝支付模块
	 */
	private void pay() {
		String info = getOrderInfo();
		String sign = Rsa.sign(info, Keys.PRIVATE);
		sign = URLEncoder.encode(sign);
		info += "&sign=\"" + sign + "\"&" + getSignType();
		final String orderInfo = info;
		new Thread() {
			public void run() {
				AliPay alipay = new AliPay(DiscountDetailActivity.this, handler);

				// 设置为沙箱模式，不设置默认为线上环境
				// alipay.setSandBox(true);
				String result = alipay.pay(orderInfo);
				Message msg = handler.obtainMessage();
				msg.what = RQF_PAY;
				msg.obj = result;
				handler.sendMessage(msg);
				LogUtil.d("wxf", "result = " + result);
			}
		}.start();
	}

	private String orderNum = null;

	private String getOrderInfo() {
		StringBuilder sb = new StringBuilder();
		sb.append("partner=\"");
		sb.append(Keys.DEFAULT_PARTNER);
		sb.append("\"&out_trade_no=\"");
		sb.append(orderNum);
		sb.append("\"&subject=\"");
		sb.append("订单");
		sb.append("\"&body=\"");
		sb.append("dfdsfdsfdsf");
		sb.append("\"&total_fee=\"");
		sb.append(discount.getPrice() + "");
		sb.append("\"&notify_url=\"");

		// 网址需要做URL编码
		sb.append(URLEncoder
				.encode("http://www.smartcity.sh/Shared/Pnotify_url"));
		// sb.append("http://www.smartcity.sh/Shared/notify_url");
		sb.append("\"&service=\"mobile.securitypay.pay");
		sb.append("\"&_input_charset=\"UTF-8");
		sb.append("\"&return_url=\"");
		sb.append(URLEncoder.encode("http://m.alipay.com"));
		sb.append("\"&payment_type=\"1");
		sb.append("\"&seller_id=\"");
		sb.append(Keys.DEFAULT_SELLER);

		// 如果show_url值为空，可不传
		// sb.append("\"&show_url=\"");
		sb.append("\"&it_b_pay=\"1m");
		sb.append("\"");

		return new String(sb);
	}

	private String getSignType() {
		return "sign_type=\"RSA\"";
	}
}
